package com.ctgu.redislock03.controller;

import com.ctgu.redislock03.entity.VoucherEntity;
import com.ctgu.redislock03.service.OrdersService;
import com.ctgu.redislock03.service.VoucherService;
import com.ctgu.redislock03.utils.ApiResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName VoucherController
 * @Author Alex2
 * @Date 2025/3/7 17:49
 **/
@RestController
@RequestMapping("/api/vouchers/")
public class VouchersController {

    @Autowired
    private VoucherService voucherService;

    @Autowired
    private OrdersService ordersService;

    @PostMapping("insertVoucher")
    public ApiResult insertVoucher(@RequestBody VoucherEntity voucherEntity) {
        return voucherService.insertVoucher(voucherEntity);
    }

    // http://localhost:8080/api/vouchers/fetchVoucher?voucherId=1&userId=1
    @GetMapping("fetchVoucher")
    public ApiResult fetchVoucher(@RequestParam("voucherId") Integer voucherId, @RequestParam("userId") Integer userId) {
        return ordersService.fetchVoucher(voucherId, userId);
    }
}
